﻿import com.dmotiko.mirador.*
import com.dmotiko.general.*
import mx.transitions.Tween;
import mx.transitions.easing.*;
import mx.utils.Delegate;

class MiradorSubBtnBar
extends MiradorBtnBar {
	private var mcBack:MovieClip;
	
	private function onLoadInit():Void {
		MiradorSite.getApp().addEventListener( WebSite.SECTION_CHANGED, Delegate.create( this, section_changed) );
	}
	
	private function section_changed():Void {
		if (MiradorMainBtnBar( _parent ).getActiveBtn().getData() != this) {
			hide();
		}
	}
	
	public function show():Void {
		if (bShowed) return;
		//MiradorSite.getApp().log("MiradorSubBtnBar | show "+this);
		this._visible = true;
		mcBack.onMouseMove = function() {
			if( (_xmouse < 0 || _xmouse > this._width) || (_ymouse < 0 || _ymouse > this._height) ){
				this._parent.section_changed();
			}
		}
		var tw:Tween = new Tween( this, "_alpha", Regular.easeIn, this._alpha, 100, 0.3, true);
		removeTween( "fadeIn" );
		registerTween( "fadeIn", tw, false, true );
		
	}
	
	public function tweenFinished( key, tween ):Void {
		if( key == "fadeIn"){
			showEnd();
		} else if( key == "fadeOut") {
			this._visible = false;
			hideEnd();
		}
	}
	
	
	public function hide():Void {
		if (!bShowed) return;
		//MiradorSite.getApp().log("MiradorSubBtnBar | hide "+this);
		var tw:Tween = new Tween( this, "_alpha", Regular.easeIn, this._alpha, 0, 0.3, true);
		removeTween( "fadeOut" );
		registerTween( "fadeOut", tw, false, true );
		delete mcBack.onMouseMove;
	}
	
	private function btnSelected( evnt ):Void	{
		if (evnt.description == "setActive") {
			super.btnSelected(evnt);
		}
		
	}
	
}